package tech.aistar.corejava.day15;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/8/3 0003
 */
@SuppressWarnings("all")
public class RunableDemo01 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <10; i++) {
            //返回的是当前正在执行的线程的引用的名称
            //名称不指定,系统会默认分配一个
            System.out.println(Thread.currentThread().getName()+":"+i);
            //让程序睡一秒钟.为了产生多线程并发访问的场景.
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class TestRunableDemo01{
    public static void main(String[] args) {
        Runnable r = new RunableDemo01();

        //创建线程对象
        Thread t1 = new Thread(r);
        Thread t2 = new Thread(r);

        t1.start();
        t2.start();
    }
}
